"use strict";
cc._RF.push(module, '781b2xD1RRP0prntmYXDiDB', 'GameGashapon');
// scripts/GameGashapon.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});
var r,
    s,
    l = t("CarConstant"),
    c = t("GlobalUserData"),
    d = t("BoxGetView"),
    h = t("HallScene"),
    p = t("Hint"),
    u = t("Util"),
    f = t("Global"),
    m = cc._decorator,
    _ = m.ccclass,
    y = m.property;
(function (t) {
  t[t.coin = 0] = "coin", t[t.diamon = 1] = "diamon", t[t.gameItem = 2] = "gameItem";
})(r || (r = {})), function (t) {
  t.gashpon_1 = "gashpon_1", t.gashpon_2 = "gashpon_2", t.gashpon_3 = "gashpon_3";
}(s || (s = {}));

var g = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.progressLayout = null, e.luckValueLabel = null, e.gashaponSk = null, e.boxPrefab = null, e.rewards = [r.coin, r.diamon, r.gameItem], e.itemsLevelProbability = [{
      level: 1,
      probability: .45
    }, {
      level: 2,
      probability: .3
    }, {
      level: 3,
      probability: .15
    }, {
      level: 4,
      probability: .07
    }, {
      level: 5,
      probability: .03
    }], e._luckValue = 0, e.maxLuckValue = 100, e.commonItemsArr = [], e.epicItemsArr = [], e._call = null, e.canDraw = !0, e.rewardArr = [], e;
  }

  return n(e, t), Object.defineProperty(e.prototype, "luckValue", {
    get: function get() {
      return this._luckValue;
    },
    set: function set(t) {
      this._luckValue = t, this.saveData(), this.luckValueLabel.string = this._luckValue.toString(), this.loadingProgress();
    },
    enumerable: !1,
    configurable: !0
  }), e.prototype.onLoad = function () {
    var t = this;
    this.node.getChildByName("bg").width = cc.view.getVisibleSize().width, this.node.getChildByName("bg").height = cc.view.getVisibleSize().height, this.loadData(), this.setCommonItems(), this.setEpicItems(), this.gashaponSk.setCompleteListener(function () {
      t.canDraw = !0, t.onRewardView(t.rewardArr);
    }), this.luckValueLabel.string = this._luckValue.toString(), this.loadingProgress();
  }, e.prototype.loadingProgress = function () {
    for (var t = this.luckValue / this.maxLuckValue, e = Math.floor(t * this.progressLayout.children.length), o = 0; o < this.progressLayout.children.length; o++) {
      this.progressLayout.children[o].active = o < e;
    }
  }, e.prototype.saveData = function () {
    cc.sys.localStorage.setItem("gashaponLuckValue", this.luckValue);
  }, e.prototype.loadData = function () {
    var t = cc.sys.localStorage.getItem("gashaponLuckValue");
    t && (this.luckValue = t);
  }, e.prototype.setCommonItems = function () {
    for (var t = 0, e = l.Basics_Body_Info; t < e.length; t++) {
      var o = e[t];
      this.commonItemsArr.push(o);
    }

    for (var i = 0, n = l.Basics_Wheel_Info; i < n.length; i++) {
      o = n[i], this.commonItemsArr.push(o);
    }

    for (var a = 0, r = l.Basics_Weapon_Info; a < r.length; a++) {
      o = r[a], this.commonItemsArr.push(o);
    }

    for (var s = 0, c = l.Basics_Tools_Info; s < c.length; s++) {
      o = c[s], this.commonItemsArr.push(o);
    }
  }, e.prototype.setEpicItems = function () {
    for (var t = 0, e = l.Basics_Body_Info; t < e.length; t++) {
      var o = e[t];
      this.epicItemsArr.push(o);
    }
  }, e.prototype.getRandomReward = function () {
    var t = Math.floor(Math.random() * this.rewards.length);
    this.rewards[t] == r.coin && this.getCoinReward(), this.rewards[t] == r.diamon && this.getDiamondReward(), this.rewards[t] == r.gameItem && this.getGameItemReward();
  }, e.prototype.getCoinReward = function () {
    var t = 1500 + Math.round(1e3 * Math.random());
    this.rewardArr.push({
      type: l.Basics_Items_Type.gold,
      num: t
    });
  }, e.prototype.getDiamondReward = function () {
    var t = 40 + Math.round(25 * Math.random());
    this.rewardArr.push({
      type: l.Basics_Items_Type.diamond,
      num: t
    });
  }, e.prototype.getGameItemReward = function () {
    for (var t = 1, e = Math.random(), o = 0; o < this.itemsLevelProbability.length; o++) {
      for (var i = 0, n = 0; n <= o; n++) {
        i += this.itemsLevelProbability[n].probability;
      }

      if (e <= i) {
        t = this.itemsLevelProbability[o].level;
        break;
      }
    }

    var a = this.commonItemsArr[Math.round(Math.random() * (this.commonItemsArr.length - 1))],
        r = this.getCarItemData(a, t);
    c["default"].saveOwnCarData([r]), this.rewardArr.push(r);
  }, e.prototype.getEpicItem = function () {
    var t = this.epicItemsArr[Math.round(Math.random() * (this.epicItemsArr.length - 1))],
        e = this.getCarItemData(t, 3);
    e.buff = l.getBuffItem(e), c["default"].saveOwnCarData([e]), this.rewardArr.push(e);
  }, e.prototype.onBtnSingleDraw = function () {
    this.canDraw && (c["default"].nDiamond < 50 ? p["default"].show("钻石不足") : (this.rewardArr = [], this.canDraw = !1, c["default"].saveDiamondData(!1, 50), this.luckValue++, this.luckValue >= this.maxLuckValue ? (this.luckValue = 0, this.gashaponSk.setAnimation(0, s.gashpon_3, !1), this.getEpicItem()) : (this.gashaponSk.setAnimation(0, s.gashpon_1, !1), this.getRandomReward())));
  }, e.prototype.onBtnFiveDraw = function () {
    var t = this;
    this.canDraw && u.Util.showRewardVideo(function () {
      t.rewardArr = [], t.canDraw = !1;

      for (var e = 0; e < 5; e++) {
        t.luckValue++, t.luckValue >= t.maxLuckValue ? (t.luckValue = 0, t.getEpicItem()) : t.getRandomReward();
      }

      for (var o = s.gashpon_1, i = 0, n = t.rewardArr; i < n.length; i++) {
        var a = n[i];
        if (a.quality) switch (a.quality) {
          case f.Quality.common:
            o = s.gashpon_1;
            break;

          case f.Quality.epic:
            o = s.gashpon_3;
            break;

          case f.Quality.Legendary:
            o = s.gashpon_2;
        }
      }

      t.gashaponSk.setAnimation(0, o, !1);
    });
  }, e.prototype.onBtnBack = function () {
    this.node.destroy();
  }, e.prototype.onRewardView = function (t) {
    var e = cc.instantiate(this.boxPrefab);
    cc.find("Canvas").addChild(e, 100), e.getComponent(d["default"]).showRewardView(t, cc.find("Canvas").getComponent(h["default"]));
  }, e.prototype.getCarItemData = function (t, e) {
    return u.Util.getItemData(t.id, t.type, e, l.GetRandomItemHp(t, e), l.GetRandomItemDamage(t, e), l.GetRandomItemElec(t, e), t.quality, t.buff);
  }, a([y(cc.Node)], e.prototype, "progressLayout", void 0), a([y(cc.Label)], e.prototype, "luckValueLabel", void 0), a([y(sp.Skeleton)], e.prototype, "gashaponSk", void 0), a([y(cc.Prefab)], e.prototype, "boxPrefab", void 0), a([_], e);
}(cc.Component);

o["default"] = g;

cc._RF.pop();